/**
 * 
 */
package com.game.jumpdino.logic;

import java.util.ArrayList;
import java.util.List;

import com.game.jumpdino.logic.visual.Avatar;
import com.game.jumpdino.logic.visual.BreakBamboo;
import com.game.jumpdino.logic.visual.Cloud;
import com.game.jumpdino.logic.visual.Dragon;
import com.game.jumpdino.logic.visual.Holder;
import com.game.jumpdino.logic.visual.Kite;
import com.game.jumpdino.logic.visual.Umbrella;
import com.game.jumpdino.logic.visual.VisualBase;

import android.content.Context;
import android.content.res.Resources;

/**
 * @author HugoGu
 *
 */
public class GameConfiguration {
	private static List<VisualConfig> visualConfigs;
	
	public static List<VisualConfig> getCurrent(){
		if (visualConfigs == null){
			visualConfigs = new ArrayList<VisualConfig>();
			
			visualConfigs.add(VisualConfig.getHolderConfig());
			visualConfigs.add(VisualConfig.getBlockerConfig());
			visualConfigs.add(VisualConfig.getFastHolderConfig());
			visualConfigs.add(VisualConfig.getBadHolderConfig());
			visualConfigs.add(VisualConfig.getSpeedUpConfig());
			visualConfigs.add(VisualConfig.getSlowdownConfig());
			visualConfigs.add(VisualConfig.getOnceHolderConfig());
			visualConfigs.add(VisualConfig.getFlyingHolderConfig());
			visualConfigs.add(VisualConfig.getMovingHolderConfig());
			visualConfigs.add(VisualConfig.getAvatarConfig());
		}
		
		return visualConfigs;
	}
	
	public static List<VisualConfig> getConfigs(int currentScore, VisualType... types){
		List<VisualConfig> result = new ArrayList<VisualConfig>();
		
		for(VisualConfig config : getCurrent()){
			for(VisualType targetType : types){
				if (config != null &&
					config.type == targetType &&
					config.showUpScore <= currentScore){
					if (config.maxShowUpCount <= 0 || 
						config.showedCount < config.maxShowUpCount){
						result.add(config);
					}
				}
			}
		}
		
		return result;
	}
	
	public static VisualBase generateVisual(VisualConfig config, Context context){
		VisualBase result = null;
		if (config.type == VisualType.Holder){
			result = new Holder();
		} else if (config.type == VisualType.Blocker){
			result = new Dragon();
		} else if (config.type == VisualType.KitHolder){
			result = new Kite();
		} else if (config.type == VisualType.BreakHolder){
			result = new BreakBamboo();
		} else if (config.type == VisualType.CloudHolder){
			result = new Cloud();
		} else if (config.type == VisualType.Avatar){
			result = new Avatar();
		} else if (config.type == VisualType.Umbrella){
			result = new Umbrella();
		} else {
			result = new VisualBase();
		}
		
		Resources resources = context.getResources();
		result.onInitialized(context);
		result.setSpeedUp(config.avatarSpeedUp);
		result.setMaxTimes(config.effectTime);
		result.setProperties(config);
		result.setImage(resources.getDrawable(config.imgID));
		result.setRenderSize(config.renderWidth, config.renderHeight);
		if (config.initialVelocity != null){
			result.setVx(config.initialVelocity.x);
			result.setVy(config.initialVelocity.y);
		}
		return result;
	}
}
